home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / jwpsrc.zip / INPUT.C < prev    next >
C/C++ Source or Header  |  1993-03-31  |  40KB  |  1,442 lines

  1. /* Copyright (C) Stephen Chung, 1991-1993.  All rights reserved. */
  2.  
  3. #include "jwp.h"
  4.  
  5.  
  6. #define STACKDEPTH      50
  7.  
  8. /*
  9. #define tolower(x)      AnsiLower ((LPSTR) (LONG) (BYTE) (x))
  10. #define toupper(x)      AnsiUpper ((LPSTR) (LONG) (BYTE) (x))
  11. */
  12. #define tolower(x)        (('A' <= (x) && (x) <= 'Z') ? (x) + 32 : (x))
  13. #define toupper(x)        (('a' <= (x) && (x) <= 'a') ? (x) - 32 : (x))
  14. #define islower(x)      ('a' <= (x) && (x) <= 'z')
  15. #define isupper(x)      ('A' <= (x) && (x) <= 'Z')
  16. #define isalpha(x)      (isupper(x) || islower(x))
  17.  
  18.  
  19. static char Typed[10] = "";
  20. static char Temp[10] = "";
  21. static KANJI InputBuffer[10];
  22. static KANJI KanjiBuffer[MAXLINELEN];
  23. static KANJI LastConv[MAXLINELEN];
  24. BYTE LastConvKey[256];
  25. static int LastLen;
  26.  
  27. static struct {
  28.     int offset;
  29.     int length;
  30. } GlossaryStack[STACKDEPTH];
  31. static int Stackp = 0;
  32.         
  33.  
  34. typedef struct {
  35.     int state;
  36.     char *input;
  37.     int next;
  38. } STATE;
  39.  
  40.  
  41. /* The State Machine */
  42.  
  43. static STATE states[] = {
  44.     { 0, "aiueo",    -1 },          /* Start */
  45.     { 0, "hmzbpr",    1 },
  46.     { 0, "kg",       30 },
  47.     { 0, "y",        27 },
  48.     { 0, "n",         3 },
  49.     { 0, "j",         4 },
  50.     { 0, "t",         5 },
  51.     { 0, "d",         6 },
  52.     { 0, "s",         7 },
  53.     { 0, "c",         8 },
  54.     { 0, "w",         9 },
  55.     { 0, "v",        13 },
  56.     { 0, "f",        14 },
  57.     { 0, "+",        24 },
  58.     { 0, "`",        -1 },
  59.     { 0, "'",        -1 },
  60.     { 0, "",         -1 },
  61.  
  62.     { 1, "aiueo",    -1 },          /* {khmgjdbpr} */
  63.     { 1, "y",         2 },
  64.  
  65.     { 2, "aueo",     -1 },          /* [...]y */
  66.  
  67.     { 3, "y",         2 },          /* n */
  68.     { 3, "aiueo'",   -1 },
  69.  
  70.     { 4, "y",         2 },          /* j */
  71.     { 4, "aiueo",    -1 },
  72.  
  73.     { 5, "y",         2 },          /* t */
  74.     { 5, "aiueo",    -1 },
  75.     { 5, "sz",       10 },
  76.     { 5, "c",        28 },
  77.  
  78.     { 6, "aiueo",    -1 },          /* d */
  79.     { 6, "y",        11 },
  80.  
  81.     { 7, "y",         2 },          /* s */
  82.     { 7, "aiueo",    -1 },
  83.     { 7, "h",        12 },
  84.  
  85.     { 8, "y",         2 },          /* c */
  86.     { 8, "h",        12 },
  87.     { 8, "i",        -1 },
  88.     { 8, "/",        -1 },
  89.  
  90.     { 9, "aieo",     -1 },          /* w */
  91.  
  92.     { 10, "u",       -1 },          /* t{sz} */
  93.  
  94.     { 11, "ui",      -1 },          /* dy */
  95.  
  96.     { 12, "aiueo",   -1 },          /* ch, sh */
  97.  
  98.     { 13, "aiueo",   -1 },          /* v */
  99.  
  100.     { 14, "aiueo",   -1 },          /* f */
  101.     { 14, "-",       -1 },
  102.  
  103.     { 22, "`",       -1 },          /* ` */
  104.  
  105.     { 23, "'",       -1 },          /* ' */
  106.  
  107.     { 24, "aiueo",   -1 },          /* + */
  108.     { 24, "t",       25 },
  109.     { 24, "y",        2 },
  110.     { 24, "w",       29 },
  111.  
  112.     { 25, "u",       -1 },          /* +t */
  113.     { 25, "sz",      26 },
  114.  
  115.     { 26, "u",       -1 },          /* +t{sz} */
  116.  
  117.     { 27, "aueo",    -1 },          /* y */
  118.     { 27, "=",       -1 },
  119.  
  120.     { 28, "y",        2 },          /* tc */
  121.     { 28, "h",       12 },
  122.     { 28, "i",       -1 },
  123.  
  124.     { 29, "a",       -1 },          /* +w */
  125.  
  126.     { 30, "aiueo",   -1 },          /* {kg}.. */
  127.     { 30, "y",        2 },
  128.     { 30, "w",       31 },
  129.  
  130.     { 31, "aieo",    -1 },          /* {kg}{uw}.. */
  131.  
  132.     { -999, NULL,    -1 }
  133. };
  134.  
  135.  
  136. /* The Conversion Tables */
  137.  
  138. static struct {
  139.     char ascii;
  140.     KANJI kanji;
  141. } JAsciiEquivalents[] = {
  142.     { ' ', 0x2121 },
  143.     { ',', 0x2122 },
  144.     { '.', 0x2123 },
  145.     { ',', 0x2124 },
  146.     { '.', 0x2125 },
  147.     { '.', 0x2126 },
  148.     { ':', 0x2127 },
  149.     { ';', 0x2128 },
  150.     { '?', 0x2129 },
  151.     { '!', 0x212a },
  152.     { '\"', 0x212b },
  153.     { '^', 0x2130 },
  154.     { '_', 0x2132 },
  155.     { '-', 0x213c },
  156.     { '-', 0x213d },
  157.     { '-', 0x213e },
  158.     { '/', 0x213f },
  159.     { '\\', 0x2140 },
  160.     { '~', 0x2141 },
  161.     { '|', 0x2143 },
  162.     { '`', 0x2146 },
  163.     { '\'', 0x2147 },
  164.     { '\"', 0x2148 },
  165.     { '\"', 0x2149 },
  166.     { '(', 0x214a },
  167.     { ')', 0x214b },
  168.     { '(', 0x214c },
  169.     { ')', 0x214d },
  170.     { '[', 0x214e },
  171.     { ']', 0x214f },
  172.     { '{', 0x2150 },
  173.     { '}', 0x2151 },
  174.     { '<', 0x2152 },
  175.     { '>', 0x2153 },
  176.     { '[', 0x215a },
  177.     { ']', 0x215b },
  178.     { '+', 0x215c },
  179.     { '-', 0x215d },
  180.     { 'x', 0x215f },
  181.     { '=', 0x2161 },
  182.     { '$', 0x2170 },
  183.     { '%', 0x2173 },
  184.     { '#', 0x2174 },
  185.     { '&', 0x2175 },
  186.     { '*', 0x2176 },
  187.     { '@', 0x2177 },
  188.     { '*', 0x2179 },
  189.     { '*', 0x217a },
  190.     { '*', 0x2228 },
  191.     { '=', 0x222e },
  192.     { '0', 0x2330 },
  193.     { '1', 0x2331 },
  194.     { '2', 0x2332 },
  195.     { '3', 0x2333 },
  196.     { '4', 0x2334 },
  197.     { '5', 0x2335 },
  198.     { '6', 0x2336 },
  199.     { '7', 0x2337 },
  200.     { '8', 0x2338 },
  201.     { '9', 0x2339 },
  202.     { '\0', 0x0000 }
  203. };
  204.  
  205. static struct {
  206.     char *string;
  207.     BYTE *real;
  208. } ComposedEquivalents[] = {
  209.     { "sha",  "\x37\x63" },
  210.     { "shi",  "\x37" },
  211.     { "shu",  "\x37\x65" },
  212.     { "she",  "\x37\x27" },
  213.     { "sho",  "\x37\x67" },
  214.  
  215.     { "ja",   "\x38\x63" },
  216.     { "ji",   "\x38" },
  217.     { "ju",   "\x38\x65" },
  218.     { "je",   "\x38\x27" },
  219.     { "jo",   "\x38\x67" },
  220.  
  221.     { "chi",  "\x41" },
  222.     { "ci",   "\x41" },
  223.  
  224.     { "cha",  "\x41\x63" },
  225.     { "chu",  "\x41\x65" },
  226.     { "che",  "\x41\x27" },
  227.     { "cho",  "\x41\x67" },
  228.  
  229.     { "tcha", "\x43\x41\x63" },
  230.     { "tchi", "\x43\x41" },
  231.     { "tci",  "\x43\x41" },
  232.     { "tchu", "\x43\x41\x65" },
  233.     { "tche", "\x43\x41\x27" },
  234.     { "tcho", "\x43\x41\x67" },
  235.  
  236.     { "tsu",  "\x44" },
  237.     { "tzu",  "\x44" },
  238.  
  239.     { "+tsu", "\x43" },
  240.     { "+tzu", "\x43" },
  241.  
  242.     { "dyi",  "\x47\x23" },
  243.     { "dyu",  "\x49\x25" },
  244.  
  245.     { "fa",   "\x55\x21" },
  246.     { "fi",   "\x55\x23" },
  247.     { "fu",   "\x55" },
  248.     { "fe",   "\x55\x27" },
  249.     { "fo",   "\x55\x29" },
  250.  
  251.     { "ye",   "\x24\x27" },
  252.  
  253.     { "kwa",  "\x2f\x21" },
  254.     { "kwi",  "\x2f\x23" },
  255.     { "kwe",  "\x2f\x27" },
  256.     { "kwo",  "\x2f\x29" },
  257.  
  258.     { "kua",  "\x2f\x21" },
  259.     { "kui",  "\x2f\x23" },
  260.     { "kue",  "\x2f\x27" },
  261.     { "kuo",  "\x2f\x29" },
  262.  
  263.     { "gwa",  "\x2f\x21" },
  264.     { "gwi",  "\x2f\x23" },
  265.     { "gwe",  "\x2f\x27" },
  266.     { "gwo",  "\x2f\x29" },
  267.  
  268.     { "gua",  "\x2f\x21" },
  269.     { "gui",  "\x2f\x23" },
  270.     { "gue",  "\x2f\x27" },
  271.     { "guo",  "\x2f\x29" },
  272.  
  273.     { "n'",   "\x73" },
  274.  
  275.     { "va",   "[\x25\x74\x25\x21]" },
  276.     { "vi",   "[\x25\x74\x25\x23]" },
  277.     { "vu",   "[\x25\x74]" },
  278.     { "ve",   "[\x25\x74\x25\x27]" },
  279.     { "vo",   "[\x25\x74\x25\x29]" },
  280.  
  281.     { "`",   "[\x21\x56]" },    /* These two are necessary because they */
  282.     { "'",   "[\x21\x57]" },    /* translate to non-ASCII equivalents   */
  283.  
  284.     { "y=",  "[\x21\x6f]" },    /* These two start with a letter */
  285.     { "f-",  "[\x21\x72]" },
  286.  
  287.     { NULL,  NULL }
  288. };
  289.  
  290. static char *direct[] = {
  291.     "+a", "a", "+i", "i", "+u", "u", "+e", "e", "+o", "o",
  292.     "ka", "ga", "ki", "gi", "ku", "gu", "ke", "ge", "ko", "go",
  293.     "sa", "za", "si", "zi", "su", "zu", "se", "ze", "so", "zo",
  294.     "ta", "da", "ti", "di", "+tu", "tu", "du", "te", "de", "to", "do",
  295.     "na", "ni", "nu", "ne", "no",
  296.     "ha", "ba", "pa", "hi", "bi", "pi", "hu", "bu", "pu", "he", "be", "pe",
  297.         "ho", "bo", "po",
  298.     "ma", "mi", "mu", "me", "mo",
  299.     "+ya", "ya", "+yu", "yu", "+yo", "yo",
  300.     "ra", "ri", "ru", "re", "ro",
  301.     "+wa", "wa", "wi", "we", "wo",
  302.     "n",
  303.     NULL
  304. };
  305.  
  306.  
  307.  
  308. BOOL ConvertOK (FILEOPTIONS *f)
  309. {
  310.     if (strlen(Typed) == 1 && strchr("AEIOU", Typed[0]) != NULL) return (TRUE);
  311.     if (SELPARA1(f) == NULL || SELPARA1(f) != SELPARA2(f)) return (FALSE);
  312.     return (TRUE);
  313. }
  314.  
  315.  
  316.  
  317. static int FindDirect (char *s)
  318. {
  319.     int i;
  320.  
  321.     for (i = 0; direct[i] != NULL; i++)
  322.         if (!strcmp(direct[i], s)) return (i);
  323.  
  324.     return (-1);
  325. }
  326.  
  327.  
  328. KANJI TranslateJAscii (KANJI ch, BOOL JtoA)
  329. {
  330.     int i;
  331.     char cch;
  332.  
  333.     if (JtoA) {
  334.         ch &= 0x7f7f;
  335.         for (i = 0; JAsciiEquivalents[i].ascii; i++) {
  336.             if (JAsciiEquivalents[i].kanji == ch) return (JAsciiEquivalents[i].ascii);
  337.         }
  338.         if (/* A */ 0x2341 <= ch && ch <= 0x235a /* Z */) return ('A' + (ch - 0x2341));
  339.         if (/* a */ 0x2361 <= ch && ch <= 0x237a /* z